package online.westonline.com.westonline.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import online.westonline.com.westonline.R;
import online.westonline.com.westonline.entry.NodeTypeBean;
import online.westonline.com.westonline.ui.NodeActivity;

/**
 * nodetype适配器
 * Created by xiatao on 2018/6/14.
 */

public class NodeTypeListAdpter extends RecyclerView.Adapter<NodeTypeListAdpter.NodeTypeViewHolder> {
    List<NodeTypeBean> typeBeans = new ArrayList<>();


    public void setTypeBeans(List<NodeTypeBean> typeBeans) {
        this.typeBeans = typeBeans;
    }

    @NonNull
    @Override
    public NodeTypeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_item, parent, false);
        return new NodeTypeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final NodeTypeViewHolder holder, final int position) {
        holder.tvNodeType.setText(typeBeans.get(position).getType());
        holder.tvNodeCount.setText(""+typeBeans.get(position).getCount());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(holder.itemView.getContext(), NodeActivity.class);
               Bundle bundle = new Bundle();
               bundle.putString("type",typeBeans.get(position).getType());
                intent.putExtras(bundle);
               holder.itemView.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return typeBeans == null ? 0 : typeBeans.size();
    }

    class NodeTypeViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_node_type)
        TextView tvNodeType;
        @BindView(R.id.tv_node_count)
        TextView tvNodeCount;
        @BindView(R.id.img_right_node)
        ImageView imgRightNode;
        public NodeTypeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
